#-*- coding: utf-8 -*-

'''
以下為覆寫Python內建的__call__()方法，當實體物件(Instance Object)被呼叫時，
對應的__call__()方法就會先自動被Python呼叫。

順便測試Notepad++的TortoiseSVN plugin工具!
'''

class Test( object ):
	def __call__( self ):
		print "You are call the Test instance as a function now!"
		
	pass
# end of class Test
	
class Animal( object ):
	def __init__( self, weight, height ):
		self.weight = weight
		self.height = height
		
	def __call__( self, name ):
		return {
			"name"   : name,
			"weight" : self.weight,
			"height" : self.height
		}
		
	pass
# end of class Animal

class Fish( Animal ):
	def __call__( self, name ):
		self.name = name
		
		return {
			"name"   : self.name,
			"weight" : self.weight,
			"height" : self.height
		}
		
	pass
# end of class Fish l


def printAnimalDetail( resultSet, message ):
	print message % ( resultSet[ "name" ], resultSet[ "weight" ], resultSet[ "height" ] )
		
test = Test()
test()	# 呼叫test變數所參照到的Test實體，因此，會去呼叫__call__()方法

dog = Animal( 12.4, 89 )
cat = Animal( 8.7, 66 )

string = "May name is %s , my weight is %s, my height is %s"
rest    = dog( "Lucky" )
print string % ( rest[ "name" ], rest[ "weight" ], rest[ "height" ] )

rest = cat( "Kitty" )
print string % ( rest[ "name" ], rest[ "weight" ], rest[ "height" ] )

# rest = apply( dog, "Rich" )		# apply內建函式，無法這樣呼叫實體
# printAnimalDetail( rest, string )

customMsg = "\nHello I am %s. I'm %s kg and %s cm..." 
rest = cat( "Kelly" )
printAnimalDetail( rest, customMsg )

# smallFish = Fish()	# 錯誤，Python的建構子是有繼承的?
bigFish = Fish( 55, 69 )
result  = bigFish( "WireShark" )
printAnimalDetail( result, customMsg )
